// ==================================================================================
// Copyright(C) 2018 FI Ltd. All rights reserved.
//
// SYSTEM NAME      : FI.Net Application Framework
// COMPONENT ID     : FI.Helpers.Data.Configuration.DataAccessSettings
// COMPONENT DESC   : Overall configuration settings for data access      helper
//
// CREATED DATE/BY : 18 Aug 2018 / Tian Mi
//
// REVISION HISTORY:   DATE/BY     SR#/CS/PM#/OTHERS    DESCRIPTION OF CHANGE
// ===================================================================================

using System.ComponentModel;
using System.Configuration;
using FI.Core.Configuration;
using FI.Core;

namespace FI.Helpers.Data.Configuration
{
    /// <summary>
    /// Overall configuration settings for data access helper.
    /// </summary>
    [ConfigurationSectionName(Constants.ConfigurationSections.DbHelper)]
    public class DataAccessSettings : ServiceLocatableSettings
    {
        private const string CommandProperty = "commands";
        private const string ParameterProperty = "parameters";
        private const string SchemaMappingProperty = "schemaMappings";
        private const string SystemFieldProperty = "systemFields";
        private const string CommandTimeoutProperty = "commandTimeout";

        /// <summary>
        /// Gets the value of commandTimeout <see cref="SystemFields"/> objects.
        /// </summary>
        /// <value>The system field.</value>
        [ConfigurationProperty(CommandTimeoutProperty, IsRequired = false, DefaultValue = "00:00:30")]
        public string CommandTimeout
        {
            get { return (string)base[CommandTimeoutProperty]; }
            set { base[CommandTimeoutProperty] = value; }
        }

        /// <summary>
        /// Gets the collection of defined <see cref="SystemFields"/> objects.
        /// </summary>
        /// <value>The system field.</value>
        [ConfigurationCollection(typeof(SystemFieldData))]
        [ConfigurationProperty(SystemFieldProperty, IsRequired = true)]
        public NamedElementCollection<SystemFieldData> SystemFields
        {
            get { return (NamedElementCollection<SystemFieldData>)base[SystemFieldProperty]; }
            set { base[SystemFieldProperty] = value; }
        }

        /// <summary>
        /// Gets the collection of defined <see cref="Commands"/> objects.
        /// </summary>
        /// <value>The command.</value>
        [ConfigurationCollection(typeof(CommandData))]
        [ConfigurationProperty(CommandProperty, IsRequired = true)]
        public NamedElementCollection<CommandData> Commands
        {
            get { return (NamedElementCollection<CommandData>)base[CommandProperty]; }
            set { base[CommandProperty] = value; }
        }

        /// <summary>
        /// Gets the collection of defined <see cref="Parameters"/> objects.
        /// </summary>
        /// <value>The parameter.</value>
        [ConfigurationCollection(typeof(ParameterData))]
        [ConfigurationProperty(ParameterProperty, IsRequired = true)]
        public NamedElementCollection<ParameterData> Parameters
        {
            get { return (NamedElementCollection<ParameterData>)base[ParameterProperty]; }
            set { base[ParameterProperty] = value; }
        }

        /// <summary>
        /// Gets the collection of defined <see cref="SchemaMappings"/> objects.
        /// </summary>
        /// <value>The schema mapping.</value>
        [ConfigurationCollection(typeof(SchemaMappingData))]
        [ConfigurationProperty(SchemaMappingProperty, IsRequired = true)]
        public NamedElementCollection<SchemaMappingData> SchemaMappings
        {
            get { return (NamedElementCollection<SchemaMappingData>)base[SchemaMappingProperty]; }
            set { base[SchemaMappingProperty] = value; }
        } 
    }
}